import threading


class Singleton(object):
    """单例类, 如果需要实现单例对象, 继承这个类即可"""
    _instance_lock = threading.Lock()

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '__instance'):
            with Singleton._instance_lock:
                setattr(cls, '__instance', super().__new__(cls, *args, **kwargs))
        return getattr(cls, '__instance')